
package ch.hearc.meteo.imp.afficheur.real.vue;

import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import ch.hearc.meteo.imp.afficheur.real.moo.StationMeteoElement;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelControl;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelGraph;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelGraphPression;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelGraphTempereature;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelStationMeteoActInfo;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelStats;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelStatsPression;
import ch.hearc.meteo.imp.afficheur.real.vue.atome.JPanelStatsTemperature;

public class JPanelInformationsMeteo extends JPanel
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/
	public JPanelInformationsMeteo()
		{
		listeStationsMeteoSelectionnee = new ArrayList<StationMeteoElement>();
		geometry();
		control();
		apparence();
		meteoDataChaned();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public void updatelisteStationMeteoSelectionnee(StationMeteoElement stationMeteoElement)
		{
		if (controlEnabled)
			{
			synchronized (listeStationsMeteoSelectionnee)
				{
				if (stationMeteoElement.getPanelStationMeteoCarteElement().isSelected() && !listeStationsMeteoSelectionnee.contains(stationMeteoElement))
					{
					listeStationsMeteoSelectionnee.add(stationMeteoElement);
					}
				else if (!stationMeteoElement.getPanelStationMeteoCarteElement().isSelected() && listeStationsMeteoSelectionnee.contains(stationMeteoElement))
					{
					listeStationsMeteoSelectionnee.remove(stationMeteoElement);
					}
				}
			}
		meteoDataChaned();
		}

	public void removeStationMeteoSelectionnee(StationMeteoElement stationMeteoElement)
		{
		if (controlEnabled)
			{
			synchronized (listeStationsMeteoSelectionnee)
				{
				if (listeStationsMeteoSelectionnee.contains(stationMeteoElement))
					{
					listeStationsMeteoSelectionnee.remove(stationMeteoElement);
					}
				}
			}
		meteoDataChaned();
		}

	public void meteoDataChaned()
		{
		panelGraphPression.refresh();
		panelGraphTemperature.refresh();
		panelStatsPression.refresh();
		panelStatsTemperature.refresh();
		panelStationMeteoActInfo.meteoDataChanged();
		panelStationMeteoActInfo.repaint();
		panelControl.refresh();
		}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/
	public void setControlEnabled(boolean enabled)
		{
		controlEnabled = enabled;
		}

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	public ArrayList<StationMeteoElement> getListeStationsMeteoSelectionnee()
		{
		return this.listeStationsMeteoSelectionnee;
		}

	public JPanelControl getPanelControl()
		{
		return panelControl;
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/
	private void apparence()
		{

		}

	private void control()
		{

		}

	private void geometry()
		{
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		panelStationMeteoActInfo = new JPanelStationMeteoActInfo(listeStationsMeteoSelectionnee);

		panelGraphPression = new JPanelGraphPression(listeStationsMeteoSelectionnee, "Temps [hh:mm:ss]", "Pression [mb]");
		panelStatsPression = new JPanelStatsPression("Pression", listeStationsMeteoSelectionnee, panelGraphPression);
		panelGraphTemperature = new JPanelGraphTempereature(listeStationsMeteoSelectionnee, "Temps [hh:mm:ss]", "Température [°C]");
		panelStatsTemperature = new JPanelStatsTemperature("Température", listeStationsMeteoSelectionnee, panelGraphTemperature);
		panelControl = new JPanelControl(listeStationsMeteoSelectionnee);

		this.add(panelStationMeteoActInfo);
		this.add(panelStatsPression);
		this.add(panelStatsTemperature);
		this.add(panelControl);

		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	//Inputs
	private ArrayList<StationMeteoElement> listeStationsMeteoSelectionnee;

	//Tools
	private JPanelStationMeteoActInfo panelStationMeteoActInfo;
	private JPanelGraph panelGraphPression;
	private JPanelStats panelStatsPression;
	private JPanelGraph panelGraphTemperature;
	private JPanelStats panelStatsTemperature;
	private JPanelControl panelControl;
	private boolean controlEnabled = true;

	}
